<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use EasyWeChat\Foundation\Application;
use App\Http\Controllers\Controller;
use EasyWeChat\Message\Article;

//素材控制器
class MaterialController extends Controller
{
    public $material;  //永久素材   
    public $temporary; //临时素材
    
    public function __construct(Application $material) {
        $this->material = $material->material;
        $this->temporary = $material->material_temporary;
    }
    
    //上传图片
    public function image(){
        $path = public_path().'/images/tong.png';
        $image = $this->material->uploadImage($path);
        return $image;
    }
    
    //上传缩略图
    public function uploadThumb(){
        $path = public_path().'/images/qq.jpg';
        $image = $this->material->uploadThumb($path);
        return $image;
    }
    
    
    //上传图文（永久，没有临时之说）
    public function uploadArticle($mediaId){
        $article = new Article([
            'title'   => '测试一下',
            'content' => '生活不止眼前的苟且，还有诗和远方',
            'thumb_media_id' => $mediaId,
        ]);
        
        $art = $this->material->uploadArticle($article);
        return $art;
    }
    
    //更新图文消息
    public function updateArticle($mediaId){
        $art = $this->material->updateArticle($mediaId, new Article([
            'title' => '更新一下试试',
            'content' => '慌慌张张，匆匆忙忙，我的理想，难道就是这样？',
            'thumb_media_id' => 'U-IurB2c4Rn8XIdJu22FyLAPJUKIkerYocx_DAPnJRo',
        ]));
        return $art;
    }
    
    //获取永久图片素材
    public function getAllImages(){
        $allImages = $this->material->lists('news');
        return $allImages;
    }
    
    public function all(){
        $stats = $this->material->stats();
        return $stats;
    }
    
}
